<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件修饰符</title>
</head>
<style>
    .wrap {
        width: 200px;
        height: 200px;
        background-color: red;
    }
    
    .box {
        width: 100px;
        height: 100px;
        background-color: skyblue;
    }
</style>

<body>
    <div id="app">
        <!-- .stop:阻止事件冒泡行为 -->
        <!-- 冒泡行为：是事件由里及外依次触发的事件 -->
        <div class="wrap" @click="wrapClick">
            <div class="box" @click.stop="boxClick"></div>
        </div>
        <!-- .prevent:阻止默认事件 -->
        <a href="http://www.baidu.com" @click.prevent="stop">百度</a>
        <!-- .capture:添加事件捕获行为 -->
        <!-- 捕获行为：是由外及里依次触发的事件，称之为捕获 -->
        <div class="wrap" @click.capture="fatherClick">
            <div class="box" @click="sonClick"></div>
        </div>
        <br/>
        <!-- .self:组织自身的事件回调,类似于阻止冒泡 -->
        <div class="wrap" @click.self="wrapClick">
            <div class="box" @click="boxClick"></div>
        </div>
        <!-- .once:事件只触发一次 -->
        <button @click.once="clickBtn">点击</button>
    </div>
</body>

</html>
<script src="js/vue3.4.21.js"></script>
<script>
    const {
        createApp,
        ref
    } = Vue

    createApp({
        setup() {
            function wrapClick() {
                console.log("点击了wrap红色盒子");
            }

            function boxClick() {
                console.log("点击了box蓝色盒子");
            }

            function stop() {
                console.log("阻止默认事件");
            }

            function fatherClick() {
                console.log("点击了红色盒子");
            }

            function sonClick() {
                console.log("点击了蓝色盒子");
            }

            function clickBtn() {
                alert("按钮被点击了")
            }
            return {
                wrapClick,
                boxClick,
                stop,
                fatherClick,
                sonClick,
                clickBtn
            }
        }
    }).mount("#app")
</script>